package algotithm.leetcode.array.test448;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/13-15:19
 * @URL https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/
 * @Title 448. 找到所有数组中消失的数字
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {4,3,2,7,8,2,3,1};
        List<Integer> disappearedNumbers = solution.findDisappearedNumbers(nums);
        for (Integer num : disappearedNumbers) {
            System.out.print(num + " ");
        }
    }

    public List<Integer> findDisappearedNumbers(int[] nums) {
        List<Integer> list = new ArrayList<>();
        int n = nums.length;
        for (int num : nums) {
            int x = (num - 1) % n;
            nums[x] += n;
        }
        for (int i  = 0; i < nums.length; i++) {
            if (nums[i] <= n) {
                list.add(i+1);
            }
        }
        return list;
    }
}
